package com.pospi.xstore.fragment;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lany.sp.SPHelper;
import com.pospi.xstore.App;
import com.pospi.xstore.R;
import com.pospi.xstore.dto.CashierMsgDto;
import com.pospi.xstore.ui.my_ui.AccountInfoActivity;
import com.pospi.xstore.ui.my_ui.ChangePwdActivity;
import com.pospi.xstore.ui.login_ui.LoginActivity;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyFragment extends BaseFragment {

    @Bind(R.id.iv_picture)
    ImageView ivPicture;
    @Bind(R.id.tv_job_number)
    TextView tvJobNumber;
    @Bind(R.id.ll_account)
    LinearLayout llAccount;
//    @Bind(R.id.ll_changePwd)
//    LinearLayout llChangePwd;
    @Bind(R.id.ll_feedback)
    LinearLayout llFeedback;
    @Bind(R.id.ll_about)
    LinearLayout llAbout;
    @Bind(R.id.ll_exit)
    LinearLayout llExit;
    private List<CashierMsgDto> msgDtos;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        ButterKnife.bind(this, view);

        tvJobNumber.setText(String.format("工号：%s", ""));
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.iv_picture, R.id.ll_account, R.id.ll_feedback, R.id.ll_about, R.id.ll_exit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_picture:
                showToast("暂不支持上传头像！");
                break;
            case R.id.ll_account:
                startActivity(AccountInfoActivity.class);
                break;
//            case R.id.ll_changePwd:
//                startActivity(ChangePwdActivity.class);
//                break;
            case R.id.ll_feedback:
                break;
            case R.id.ll_about:
                break;
            case R.id.ll_exit:
                new AlertDialog.Builder(getActivity())
                        .setTitle("退出提示")
                        .setMessage("确定要退出当前账户吗?")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SPHelper.getInstance().putBoolean("isLogin",false);

                                //删除已经存储的登录的信息

                                startActivity(LoginActivity.class);
                                getActivity().finish();
                            }
                        })
                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).create().show();
                break;
        }
    }
}
